var app = angular.module('student_manage',['ng']);

app.controller('studentListController',function($scope,$http){
    $scope.fetchList = function () {
        $http.get('getAll').success(function (result) {
            $scope.students = result.data;
        });
    };
    $scope.add = function(){
        $http({
            method:'post',
            url:'add',
            data:$scope.user
        }).success(function (data) {
            if(data.code=='c0000'){
                toastr.info("添加成功");
                $scope.fetchList();
                $scope.user={
                    realname:"",
                    code:""
                };
            }else{
                toastr.error("后台报错");
            }
        });
    };
    $scope.deleteStudent = function(student){
        $http({
            method:'get',
            url:'deleteStudent?id='+student.id,
        }).success(function(data){
            if(data.code=='c0000'){
                toastr.info("删除成功");
                $scope.fetchList();
            }
        });

    }

    $scope.fetchList();
});
